#!/usr/bin/python
import sys, os #--
import pygst #--
pygst.require("0.10") #--
import gst #--
import pygtk #--
pygtk.require('2.0') #--
import gtk, gtk.glade #--
#--
class Bass:#--
    def __init__(self):#--
        gladeFile = os.path.join(os.path.dirname(__file__,), 'bass.glade') #--
        self.xml = gtk.glade.XML(gladeFile, None) #--
        self.xml.signal_autoconnect(self) #--
        window = self.xml.get_widget("main") #--
        window.connect('delete-event', gtk.main_quit) #--
        window.show_all() #--
#--
        self.pipeline = gst.Pipeline()
        gstElemMake = gst.element_factory_make
#=000
#=010 the top of the pipeline
        filesrc = gstElemMake("filesrc") #010
        filesrc.set_property('location', sys.argv[1]) #010
        mad = gstElemMake("mad") #010
        tee = gstElemMake("tee", "t") #010
#=015 the left-hand pipeline
        queue0 = gstElemMake("queue") #015
        audioconvert0 = gstElemMake("audioconvert") #015
        lpf = gstElemMake("ladspa-lpf") #015
        self.bass = gstElemMake("volume", "bass") #015
        audioconvert1 = gstElemMake("audioconvert") #015
#=020 the tail of the pipeline
        adder = gstElemMake("adder") #020
        self.master = gstElemMake("volume", "master") #020
        sink = gstElemMake("alsasink") #020
        sink.set_property("device", "plughw:2") #020
#=030 add them all
        self.pipeline.add(filesrc, mad, tee, queue0, audioconvert0, #030
                          lpf, self.bass, audioconvert1, adder, #030
                          self.master, sink) #030
#=040 connect the top, left, and tail
        gst.element_link_many(filesrc, mad, tee, queue0, audioconvert0, #040
                              lpf, self.bass, audioconvert1, adder, #040
                              self.master, sink) #040
#=050 make the right hand branch
        queue1 = gstElemMake("queue") #050
        audioconvert2 = gstElemMake("audioconvert") #050
        self.pipeline.add(queue1, audioconvert2) #050
        gst.element_link_many(queue1, audioconvert2) #050

#=060 get a new pad from the tee 
        tpad1 = tee.get_pad('src1') #060
#=070 get pad from the 2nd queue 
        q1sink = queue1.get_pad('sink') #070
#=080 hook them together
        tpad1.link(q1sink) #080
#=090 link the 2nd branch to adder
        audioconvert2.link(adder) #090
#--
    def on_playButton_clicked(self, widget):#--
        self.pipeline.set_state(gst.STATE_PLAYING)#--
#--
    def on_pauseButton_clicked(self, widget):#--
        self.pipeline.set_state(gst.STATE_PAUSED)#--
#--
    def on_masterScale_value_changed(self, w):#--
        scale = w.get_value() #--
        self.master.set_property('volume', scale/100)#--
#--
    def on_bassScale_value_changed(self, w):#--
        scale = w.get_value() #--
        self.bass.set_property('volume', scale/100)#--
#--
    def on_quit_activate(self, widget):#--
        gtk.main_quit()#--
#--
if __name__ == "__main__":#--
    bass=Bass()#--
    gtk.main()#--
